<template>
	<view class="u-p-l-10 u-p-r-10">
		<u-navbar :is-back="false">
			<view style="display: flex;justify-content: center;align-items: center;">	
			</view>
		</u-navbar>
		<view>
			<!-- 轮播图 -->
			<!-- #ifndef MP-WEIXIN --> 
				<!-- <u-swiper :list="swiperList" height="350"></u-swiper> -->
			<!-- #endif -->
			<u-swiper :list="swiperList" height="350"></u-swiper>
		</view>
		<view>
			<view class="rowClass">
				<u-grid :col="3">
					<u-grid-item v-for="(item,index) in navList1" :key="index" @click="clickNav(item)">
						<image :src="item.src" style="width: 90rpx;height: 90rpx;" mode="widthFix"></image>
						<view class="tabName">{{item.name}}</view>
					</u-grid-item>
				</u-grid>
				<u-grid :col="3">
					<u-grid-item v-for="(item,index) in navList2" :key="index" @click="clickNav(item)">
						<image :src="item.src" style="width: 90rpx;height: 90rpx;" mode="widthFix"></image>
						<view class="tabName">{{item.name}}</view>
					</u-grid-item>
				</u-grid>
			</view>
			<u-gap height="10"></u-gap>
			<!-- <view @click="notice">
				<u-notice-bar mode="vertical" :list="noticeList" type="primary" more-icon
				bg-color="#fff" :duration="5000" border-radius="15"></u-notice-bar>
			</view> -->
			<u-gap height="5"></u-gap>
		</view>
	</view>
</template>

<script>
	import config from "@/common/config.js" // 全局配置文件
	export default {
		data() {
			return {
				keyword: '',
				pageNum: 1,
				pageSize: 20,
				scrollTop: 0,
				houseList: [],
				swiperList: [],
				noticeList: [],
				navList:[
				   {name:"全球好物",src:"/static/img/index/cover_2022/index_cover1.png",type:"0"},
				   {name:"全球素材",src:"/static/img/index/cover_2022/index_cover2.png",type:"1"},
				   {name:"全球文案",src:"/static/img/index/cover_2022/index_cover3.png",url:"/pages/center/tips"},
				   {name:"视频下载",src:"/static/img/index/cover_2022/index_cover4.png",type:"2"},
				   {name:"视频回收",src:"/static/img/index/cover_2022/index_cover1.png",type:"0"},
				   {name:"敬请期待",src:"/static/img/index/cover_2022/index_cover2.png",type:"1"}
				],
				navList1:[
				   {name:"全球好物",src:"/static/img/index/home/haowu1.png",type:"2"},
				   {name:"全球素材",src:"/static/img/index/home/sucai2.png",type:"9"},
				   {name:"全球文案",src:"/static/img/index/home/wendang3.png",type:"13"}
				],
				navList2:[
				   {name:"视频下载",src:"/static/img/index/home/xiazai4.png",type:"14"},
				   {name:"视频回收",src:"/static/img/index/home/huishou5.png"},
				   {name:"敬请期待",src:"/static/img/index/home/qidai6.png"}
				],
				loadStatus: 'loadmore',
				flowList: [],
				uvCode: uni.getStorageSync('uvCode')
			}
		},
		onLoad() {
			// 检查是否已选择城市，如果未选择，跳转到选择城市页面
			// this.checkCity();
			// 获取数据
			this.findBannerList();
			// this.findHouseList();
			// this.getNoticecList();
			// 流量统计
			// this.appSysFlowInfo();
			// uni.$on('findIndexHouseList', (obj) => {
			// 	// 获取数据
			// 	this.findHouseList(1);
			// })
		},
		onUnload() {
			// 移除监听事件  
			//uni.$off('findIndexHouseList');
		},
		onPageScroll(e) {
		    this.scrollTop = e.scrollTop;
		},
		// onReachBottom() {
		//     this.loadStatus = 'loading';
		//     // 获取数据
		// 	//this.findHouseList()
		// },
		// 下拉刷新
		// onPullDownRefresh() {
		// 	// 获取数据
		// 	this.findHouseList(1);
		// 	// 关闭刷新
		// 	uni.stopPullDownRefresh();
		// },
		methods: {
			location(){
				  this.$u.route({
					url: 'pages/location/location',
				  })
			},
			search(){
				this.$u.route({
					url: 'pages/search/search',
				})
			},
			notice(){
				this.$u.route({
					url: 'pages/notice/notice'
				})
			},
			findBannerList(){
				let url = "/api/banner/list";
				this.$u.get(url, {}).then(result => {
					//修改banner数据
					const data = result.data;
					var list2 = []
					for (let i = 0; i < data.length; i++) {
						let item = data[i]
						item.image = config.staticUrl + item.bannerPic
						list2[i] = item
					}
					this.swiperList = list2
				});
			},
			// findHouseList(type = 0) {
			// 	if(type == 1){
			// 		this.pageNum = 1
			// 		this.flowList = []
			// 		this.$refs.uWaterfall.clear();
			// 	}
			// 	let url = "/api/houseApi/findHouseRoomList";
			// 	this.$u.get(url, {
			// 		state:1,
			// 		villageCity:uni.getStorageSync('lifeData').vuex_city,
			// 		pageNum: this.pageNum,
			// 		pageSize: this.pageSize,
			// 		orderByColumn: 'update_time,create_time',
			// 		isAsc: 'desc'
			// 	}).then(result => {
			// 		const data = result.rows;
			// 		if(this.pageNum>1 && data.length < this.pageSize){
			// 			return this.loadStatus = 'nomore';
			// 		}
			// 		this.houseList = data;
			// 		for (let i = 0; i < this.houseList.length; i++) {
			// 		    // 先转成字符串再转成对象，避免数组对象引用导致数据混乱
			// 		    let item = this.houseList[i]
			// 			if(!item.faceUrl.includes(config.staticUrl)){
			// 				item.image = config.staticUrl+item.faceUrl
			// 			}else{
			// 				item.image = item.faceUrl
			// 			}
			// 			if(item.type == 0){
			// 				item.type = '整租'
			// 			}else if(item.type == 1){
			// 				item.type = '合租'
			// 			}
			// 			if(item.roomType == 1){
			// 				item.roomType = '主卧'
			// 			}else if(item.roomType == 2){
			// 				item.roomType = '次卧'
			// 			}else{
			// 				item.roomType = '未知'
			// 			}
			// 			if(this.$u.test.isEmpty(item.houseNum)){
			// 				item.houseNum = ''
			// 			}
			// 			if(this.$u.test.isEmpty(item.houseHall)){
			// 				item.houseHall = ''
			// 			}
			// 			if(this.$u.test.isEmpty(item.toiletNum)){
			// 				item.toiletNum = ''
			// 			}
			// 		    this.flowList.push(item);
			// 		}
			// 		++ this.pageNum 
			// 		this.loadStatus = 'loadmore';
			// 	});
			// },
			clickSearch() {
			    this.$u.route('/pages/search/search');
			},
			clickImage(houseId) {
				this.$u.route({
					url: '/pages/detail/detail',
					params: {
						houseId: houseId
					}
				})
			},
			clickNav(item){
				if(!item.type){
					this.$mytip.toast('敬请期待')
				}else{
					return this.$u.route({
						url: '/pages/search/searchList',
						params: {
							type: item.type,
							titleName: item.name
						}
					})
				}
			},
			code(){
				this.$mytip.toast('请咨询作者')
			},
			appSysFlowInfo(){
				// 流量统计
				let uvCode = uni.getStorageSync("uvCode");
				let url = "https://sourcebyte.cn/api/flow/upFlow?type=MINI&uvCode=" + uvCode;
				uni.request({
				  url: url,
				  method: "POST",
				  success: (res) => {
					uni.setStorageSync("uvCode", res.data.data);
				  },
				});
			},
			server(){
				// window.open ('https://sourcebyte.cn')
				uni.makePhoneCall({
				  phoneNumber: "18720989281",
				});
			},
			getNoticecList(){
				let url = "/api/notice/findNoticeList";
				this.$u.get(url,{
					pageNum:1,
					pageSize:50,
					orderByColumn:'create_time',
					isAsc:'desc'
				}).then(obj => {
					let data = obj.rows
					data.filter(item=>{
						this.noticeList.push(item.noticeTitle)
					})
				});
			},
			moreInfo(){
				uni.navigateToMiniProgram({
					appId:'wxbca64173e772915e',// 此为开源字节appid
					path:'/pages/index/index',// 此为开源字节首页路径
					envVersion:"release",
					success: res => {
						 // 打开成功
						 console.log("打开成功", res);
					},
					fail: err => {
						 console.log(err);
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.nomore {
		background-color: $u-bg-color;
	}
	
	.search{
		width: 54px;
		height: 44px;
		
		&:active{
			background-color: $u-bg-color;
		}
	}
	
	.rowClass{
		border-radius: 8px;
		background-color: rgb(255, 255, 255);
		margin-top: 10rpx;
	}
	
	.hoverClass{
		background-color: #E4E7ED;
	}
	
	.tabName{
		font-size: 28rpx;
		color: $u-main-color;
	}
	
	.demo-warter {
	    border-radius: 8px;
	    margin-top: 3px;
	    background-color: #ffffff;
	    padding: 3px;
	    position: relative;
	}
	
	.u-close {
	    position: absolute;
	    top: 20rpx;
	    right: 20rpx;
	}
	
	.item-cover {
	    font-size: 55rpx;
	    color: $u-type-warning;
	}
	
	.item-title {
	    font-size: 28rpx;
	    color: $u-main-color;
	    font-weight: bold;
		padding-top: 5rpx;
		padding-left: 10rpx;
	}
	
	.item-price {
	    font-weight: normal;
	    font-size: 32rpx;
	    color: $u-type-warning;
	}
	
	.item-desc {
	    font-weight: normal;
	    font-size: 26rpx;
	    color: $u-tips-color;
		padding-bottom: 5rpx;
		padding-left: 10rpx;
	}
	
	.item-tag {
	    font-size: 24rpx;
	    color: $u-tips-color;
	    margin-top: 3px;
	}
	
	.buttom {
		.loginType {
			font-size: 14px;
			position: fixed;
			right: 30rpx;
			bottom: 300rpx;
			width: 60px;
			height: 60px;
			padding: 4px;
			cursor: pointer;
			background: #FFF;
			text-align: center;
			line-height: 60px;
			border-radius: 100%;
			-webkit-box-shadow: 0px 1px 20px 0px rgba(0,0,0,0.1),inset 0px -1px 0px 0px rgba(0,0,0,0.1);
			box-shadow: 0px 1px 20px 0px rgba(0,0,0,0.1),inset 0px -1px 0px 0px rgba(0,0,0,0.1);
		}
	}
</style>
